//
//  NSArray+EX.m
//  BaiduTravel
//
//  Created by LiZujian on 13-1-26.
//
//

#import "NSArray+EX.h"

@implementation NSArray (EX)

- (NSArray *)head:(NSUInteger)count
{
	if ( [self count] < count )
	{
		return self;
	}
	else
	{
		NSMutableArray * tempFeeds = [NSMutableArray array];
		for ( NSObject * elem in self )
		{
			[tempFeeds addObject:elem];
			if ( [tempFeeds count] >= count )
				break;
		}
		return tempFeeds;
	}
}

- (NSArray *)tail:(NSUInteger)count
{
	NSRange range = NSMakeRange( self.count - count, count );
	return [self subarrayWithRange:range];
}

- (id)safeObjectAtIndex:(NSUInteger)index
{
	if ( index >= self.count )
		return nil;
    
	return [self objectAtIndex:index];
}
@end

@implementation NSMutableArray (EX)

//-(id)safeObjectAtIndex:(NSUInteger)index
//{
//    if ( index >= self.count )
//		return nil;
//    
//	return [self objectAtIndex:index];
//}

@end
